<template>
  <div class="detail-wrapper">
    <view class="detail-top">
      <span v-if="noticeDetail.isTop === true" class="settop">置顶</span>
      <span class="notice-title">{{ noticeDetail.title }}</span>
    </view>
    <view class="detail-info">
      <span class="notice-author">{{ noticeDetail.createUserName }}</span>
      <span class="notice-time">{{ noticeDetail.gmtCreate | formatDateAll(noticeDetail.gmtCreate) }}</span>
    </view>
    <view class="notice-content">
      <uParse :content="noticeDetail.contentHasStyle"></uParse>
    </view>
    <view class="notice-author" style="padding-top: 10px;" v-if="file.length!==0">
      附件：
      <text style="font-size:12px;color:#9c9c9c">长按文件可复制地址</text>
    </view>
    <view style="margin-top:12px;font-size:12px;color:#9c9c9c" v-for="i in file" :key="i.name" @click="setClipboardData(i)">{{i.name}}</view>
  </div>
</template>

<script>
import uParse from '@/components/gaoyia-parse/parse.vue'
import { empNoticesInfo, readUserNotice } from "@/services/contract";
import { formatDateAll } from "@/utils/tools.js";
export default {
  components: { uParse },
  filters: {
    formatDateAll: formatDateAll,
  },
  data() {
    return { file: [], empNoticeId: "", noticeDetail: {} };
  },
  onLoad(options) {
    this.empNoticeId = options.id;
    this.getNoticeDetail(this.empNoticeId);
    this.readUserNotice();
  },
  methods: {
    readUserNotice() {
      readUserNotice(this.empNoticeId, this.$store.state.site.employeeId)
        .then((res) => {})
        .catch((err) => {
          console.log("debug log --> ", err);
        });
    },
    setClipboardData(e) {
      wx.setClipboardData({
        data: e.url,
        success(res) {
          wx.getClipboardData({
            success(res) {
              console.log(res.data); // data
            },
          });
        },
      });
    },
    getNoticeDetail(empNoticeId) {
      empNoticesInfo(empNoticeId).then((res) => {
        this.noticeDetail = res;
        this.file = JSON.parse(this.noticeDetail.file);
      });
    },
    handleTable(content) {
      if (content) {
        const content_new = content
          .replaceAll("<table", '<div class="table"')
          .replaceAll("</table>", "</div>")
          .replaceAll("<tr", '<div class="tr"')
          .replaceAll("</tr>", "</div>")
          .replaceAll("<th", '<div class="th"')
          .replaceAll("</th>", "</div>")
          .replaceAll("<td", '<div class="td"')
          .replaceAll("</td>", "</div>");
        console.log(content_new);
        return content_new;
      }
      return null;
    }
  },
};

</script>
<style>
.detail-wrapper {
  width: 100%;
}
</style>